#include <bits/stdc++.h>
using namespace std;

int main()
{
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    int t;
    for (int i = 1; i <= n; ++i)
    {
        cin >> t;
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> t;
    }
    int k = 0, tmp = n;
    while (tmp)
    {
        tmp /= 2;
        k++;
    }
    string s;
    for (int i = 1; i <= k; ++i)
    {
        cin >> s;
    }
    int T;
    cin >> T;
    for (int i = 1; i <= T; ++i)
    {
        for (int j = 1; j <= 4; ++j)
        {
            cin >> t;
        }
        cout << 1 << endl;
    }
    return 0;
}
